using System.Collections.Generic;
using System.Linq;

namespace Kiwi.Container
{
    public class CircularComponentActivationException : ContainerException
    {
        public CircularComponentActivationException(IComponentRegistration registration,
                                                    IEnumerable<IComponentRegistration> activated)
        {
            Registration = registration;
            Activated = activated.ToArray();
        }

        public IComponentRegistration Registration { get; set; }
        public IComponentRegistration[] Activated { get; set; }

        public override string Message
        {
            get
            {
                return
                    string.Format(
                        "Component {0} has circular dependencies. Other components in the activation context are of types {{{1}}}.",
                        Registration.ComponentType,
                        string.Join(",", Activated.Select(c => c.ComponentType.ToString()).ToArray())
                        );
            }
        }
    }
}